<?php

namespace App\Http\Controllers\Api;

use App\Service\SmsService;
use Illuminate\Http\Request;
use App\Service\UploadService;
use AlibabaCloud\Client\Exception\ClientException;

class IndexController
{
    /**
     * 发送短信验证码
     *
     * @param Request $request
     *
     * @throws ClientException
     */
    public function sendCode(Request $request)
    {
        $ip     = $request->ip();
        $mobile = $request->input('mobile');

        return successJson(SmsService::sendCode($mobile, $ip));
    }

    /**
     * base字符串上传图片.
     *
     * @param Request $request
     */
    public function uploadImageBase64(Request $request)
    {
        $file = $request->input('file');

        return successJson(UploadService::base64Image($file));
    }
}
